package showtime.framework.manager.supportClasses.cycle
{

	import flash.utils.getTimer;
	
	/** 
	 * @project showtime
	 * @author yinhao
	 * @date 2010-12-16
	 *
	 */
	
	public class WrapperCycleUnit implements ICycleUnit
	{
		/**
		 * Cycle unit source. 
		 */		
		public var source:ICycleUnit = null;
		
		public var elapseTime:int = 0;

		/**
		 * Constructor. 
		 * 
		 */		
		public function WrapperCycleUnit(unit:ICycleUnit)
		{
			source = unit;
		}
	
		/**
		 * Execute unit logic work. 
		 * 
		 */		
		public function execute():void
		{
			// Calculate time.
			if (elapseTime == 0)
			{
				elapseTime = getTimer();
			}
			
			if (((getTimer() - elapseTime)) >= source.getInterval())
			{
				source.execute();
				
				elapseTime = getTimer();
								
			}
		
		}
		
		public function getUnitName():String
		{
			return source.getUnitName();
		}
		
		public function getInterval():int
		{
			return source.getInterval();
		}

	}
}